home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- *
- * Apple Macintosh Developer Technical Support
- *
- * Installer 3.4.3 sample: UserChkGestaltFunction
- *
- * File: UserChkGestaltFunction.c - c Source
- *
- * by: Rich Kubota
- *
- *
- * purpose: Use as a alternate means of identifying whether a Gestalt selector
- * is available. The CheckGestalt clause requires the scriptor to enter
- * all valid Gestalt selector results. This poses a future compatibility
- * problem in that one would like to simply know that a gestalt selector
- * exists and not have to worry about matching the result in order to pass
- * the clause. This user function simply requires that the scriptor pass in
- * the gestalt selector to check for. A true result is returned if the selector
- * is found, false otherwise or if the Gestalt trap was not available.
- * Copyright © 1988 - 1994 Apple Computer, Inc.
- * All rights reserved.
- *
- *----------------------------------------------------------------------------*/
- #if 0
- c -b UserChkGestaltFunction.c
- Link -ra =resPurgeable -rt infn=1002 -rn -m USERCHKGESTALTFUNCTION -t rsrc -c RSED ∂
- UserChkGestaltFunction.c.o ∂
- "{Libraries}"Interface.o ∂
- -o UserChkGestaltFunction.rsrc
- #endif
-
- /* applec is only defined by MPW C so we can use it to make versions that work
- with MPW C and THINK C
- */
- #ifdef applec
- #include <Types.h>
- #include <Traps.h>
- #include <OSUtils.h>
- #include <GestaltEqu.h>
- #endif
-
-
- /****************** function prototypes *********************/
-
- short NumToolboxTraps(void);
- TrapType GetTrapType(unsigned short theTrap);
- Boolean TrapAvailable(unsigned short theTrap);
-
- /**************************************************************/
-
- pascal Boolean UserChkGestaltFunction(short targetVRefNum, long blessedID, long selector)
- {
- #pragma unused (blessedID, targetVRefNum)
-
- OSErr err;
- long result;
-
- if (TrapAvailable(_Gestalt)) // check whether the Gestalt trap is available
- {
- err = Gestalt((OSType)selector, &result); // pass the selector to the Gestalt call
- return (err == noErr); // return result
- }
- else
- return false; // gestalt not found, return false
- }
-
- /******** The following code is from IM VI *******/
-
- short NumToolboxTraps(void)
- {
- if (NGetTrapAddress(_InitGraf, ToolTrap) ==
- NGetTrapAddress(0xAA6E, ToolTrap))
- return(0x200);
- else
- return(0x400);
- }
-
- #define TrapMask 0x0800
-
- TrapType GetTrapType(unsigned short theTrap)
- {
- if (theTrap & TrapMask)
- return (ToolTrap);
- else
- return (OSTrap);
- }
-
- Boolean TrapAvailable(unsigned short theTrap)
- {
- TrapType theType;
-
- theType = GetTrapType(theTrap);
- if (theType == ToolTrap) {
- theTrap &= 0x07FF;
- if (theTrap >= NumToolboxTraps())
- theTrap = _Unimplemented;
- }
-
- return (NGetTrapAddress(theTrap, theType) !=
- NGetTrapAddress(_Unimplemented, ToolTrap));
- }
-